<?php
if(!defined('BZ_XTBLOG') || !defined('BZ_WJSCUZ')) {
	exit('Access Denied');
}
$fid =verify_id($_GET['fid']);
$act =$_GET['act'];
$wzxx_title ='附件操作-'.$wzxx_title.'';
$wzxx_gj    ='附件操作-'.$wzxx_gj.'';
$wzxx_ms    ='附件操作-'.$wzxx_ms.'';
$forumfj=$db->get_one('forum_data'," `id` ='$fid' ",'');
$forum=$db->get_one('forum'," `id` ='$forumfj[fid]' AND `sz_sc` ='0'",'');
$url_fj=Bingz_upload_images('data/forum/'.$forumfj[url]);
$fjid =$forumfj[id];
$fid =$forumfj[fid];
if(!$user_uid ){
	   $pdid='1';
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else if(!$forumfj){
     $pdid='2';
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else if(!file_exists($url_fj)){
     $pdid='3';
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else if( $act == 'gm' ){
	   if($forumfj['money'] > $user['money']){
	       $pdid='4';
	   }elseif(Bingz_management($user_uid,'money','-'.$forumfj[money].'','支付购买收费附件！') > '0'){
	       $db->insert('forum_data_user',array('id' => 'NULL' ,' uid' => $user_uid,'fid' => $forumfj[id] ,' money' => $forumfj[money]));
         $db->update('forum_data',array( 'gmcs' => '+1' ),"`id` ='$forumfj[id]' ");
	       Bingz_management($forum[uid],'money','+'.$forumfj[money].'','赚取会员('.$user_name.')购买附件！');
	       Bingz_message_post('0',$forum[uid],'你好！你收费附件帖子【[url=index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=viewthread&fid='.$forum[id].']'.$forum[name].'[/url]】！收获'.$wzxx_jb_name.':'.$forumfj['money'].'');
	       $pdid='5';
     }else{
	       $pdid='6';
	   }
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else if($forumfj['money'] > '0' && !$db->get_one('forum_data_user'," `uid` ='$user_uid' AND `fid` =' $forumfj[id]'",'')){
     $pdid='7';
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else if( $act == 'ck' ){
	   $xzcs=$forumfj[xzcs];
	   $size=$forumfj[size];
	   $pdid='8';
     @include template('head');
     @include template('forum/forum_attachment');
     @include template('foot');
}else{
    $db->update('forum_data',array('xzcs' => '+1' ),"`id` ='$forumfj[id]' ");
    $file_path=MBLOG_ROOT.$url_fj;
    Bingz_cache_html_delete('forum','forum_'.$forumfj[fid].'');
    Bingz_download($url_fj,$forumfj[name]);
/*
$fname=$url_fj;
$fp = fopen($fname,'rb'); 
$fsize = filesize($fname); 
if (isset($_SERVER['HTTP_RANGE']) && ($_SERVER['HTTP_RANGE'] != "") && preg_match("/^bytes=([0-9]+)-$/i", $_SERVER['HTTP_RANGE'], $match) && ($match[1] < $fsize)) { 
   $start = $match[1]; 
} else { 
   $start = 0; 
} 
Header("Cache-control: public"); 
Header("Pragma: public"); 
if ($start > 0) {
fseek($fp, $start);
Header("HTTP/1.1 206 Partial Content");
Header("Content-Length: ".($fsize - $start));
Header("Content-Ranges: bytes".$start."-".($fsize - 1)."/".$fsize);
} else {
Header("Content-Length: ".$fsize."");
Header("Accept-Ranges: bytes");
}
Header("Content-Type: application/octet-stream");
Header("Content-Disposition: attachment;filename=".$forumfj[name]."");
fpassthru($fp);
*/


/*
    $file_path=MBLOG_ROOT.$url_fj;
    $fp=fopen($file_path,"r"); 
    $file_size=filesize($url_fj);
Header("Content-type: application/octet-stream"); 
Header("Accept-Ranges: bytes"); 
Header("Accept-Length:".$file_size); 
Header("Content-Disposition: attachment; filename=".$forumfj[name]); 
$buffer=1024; 
$file_count=0;
while(!feof($fp) && $file_count < $file_size){
       $file_con=fread($fp,$buffer); 
       $file_count+=$buffer; 
       echo $file_con; 
}
fclose($fp);

*/
}
?>